package com.example.chatplatform.controller;

import com.example.chatplatform.model.vo.CronyMessageVO;
import com.example.chatplatform.model.vo.GroupMemberVO;
import com.example.chatplatform.model.vo.GroupMessageVO;
import com.example.chatplatform.model.vo.MessageListVO;
import com.example.chatplatform.result.Result;
import com.example.chatplatform.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    public MessageService messageService;

    //查询聊天列表
    @GetMapping("/messageList")
    private Result messageList(@RequestParam Integer userId) {
        MessageListVO messageLists = messageService.messageList(userId);
        if (messageLists != null) {
            return Result.success(messageLists);
        } else {
            return Result.error("查询失败");
        }
    }

    //搜索聊天列表
    @GetMapping("/searchChat")
    private Result searchChat(@RequestParam Integer userId, @RequestParam String searchChatValue) {
        MessageListVO messageLists = messageService.searchChat(userId, searchChatValue);
        if (messageLists != null) {
            return Result.success(messageLists);
        } else {
            return Result.error("查询失败");
        }
    }

    //查询好友聊天记录
    @GetMapping("/cronyChatRecord")
    private Result cronyChatRecord(@RequestParam Integer userId, Integer cronyId) {
        CronyMessageVO cronyMessageVO = messageService.cronyChatRecord(userId, cronyId);
        if (cronyMessageVO != null) {
            return Result.success(cronyMessageVO);
        } else {
            return Result.error("查询失败");
        }
    }

    //查询群聊聊天记录
    @GetMapping("/groupChatRecord")
    private Result groupChatRecord(@RequestParam Integer userId, Integer groupId) {
        GroupMessageVO groupMessageVO = messageService.groupChatRecord(userId, groupId);
        if (groupMessageVO != null) {
            return Result.success(groupMessageVO);
        } else {
            return Result.error("查询失败");
        }
    }

}
